import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import service.AirlineReservationServiceProxy;
import bean.FlightUpdate;
import bean.Journey;
import constants.AirlineReservationServiceConstants;


public class RetrieveUpdatesServlet extends HttpServlet{

	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
	
		AirlineReservationServiceProxy proxy = new AirlineReservationServiceProxy(
				AirlineReservationServiceConstants.SERVICE_URL);
	
		
		FlightUpdate[] flightUpdates = proxy.retrieveFlightUpdate(Long.parseLong(req.getParameter("personId")));
		
		List<FlightUpdate> lstFlightUpdates = new ArrayList<FlightUpdate>();
		
		if(flightUpdates!=null){
			lstFlightUpdates = Arrays.asList(flightUpdates);
			System.out.println("Inside Flight Updates..........." + lstFlightUpdates.size() + ".........."+req.getParameter("personId"));
			req.setAttribute("lstFlightUpdates",lstFlightUpdates);
			req.getRequestDispatcher("viewFlightUpdates.jsp").include(req, resp);
		}
		
	
		
		
		
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	
}
